#!/usr/bin/env python3

import os
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('AyatanaAppIndicator3', '0.1')
gi.require_version('Notify', '0.7')
from gi.repository import Gtk, Gdk, GLib, AyatanaAppIndicator3

desktop = os.environ.get("echo $XDG_CURRENT_DESKTOP", "")

if desktop == "KDE":
    APPINDICATOR_ID = ""
else:
    APPINDICATOR_ID = "pdc"

def script1(widget):
    os.popen("~/.pdc/progressbar")

def script2(widget):
    os.popen("pkill -SIGSTOP axel > /dev/null 2>&1")
    os.popen("/usr/share/pdc/notify/pdc_pause.py")

def script3(widget):
    os.popen("pkill -SIGCONT axel > /dev/null 2>&1")
    os.popen("/usr/share/pdc/notify/pdc_resume.py")

def script4(widget):
    os.popen("/usr/share/pdc/notify/about/'PCLinuxOS Distro Choice'")

def script5(widget):
    os.popen("~/.pdc/stop")

def build_menu():
    menu = Gtk.Menu()
    items = [
        ("⌛️ Progress", script1, "Download Progress"),
        ("🟠️ Pause", script2, "Pause Progress"),
        ("🟢️ Resume", script3, "Resume Progress"),
        ("💬️ About", script4, "About PDC"),
        ("🔴️ Stop", script5, "Stop Downloading")

    ]

    for label, callback, tip in items:
        item = Gtk.MenuItem(label=label)
        item.connect('activate', callback)
        item.set_tooltip_text(tip)
        menu.append(item)

    menu.show_all()
    return menu

indicator = AyatanaAppIndicator3.Indicator.new(
    APPINDICATOR_ID,
    "/usr/share/pdc/icons/pdc.png",
    AyatanaAppIndicator3.IndicatorCategory.APPLICATION_STATUS
)

indicator.set_status(AyatanaAppIndicator3.IndicatorStatus.ACTIVE)
indicator.set_menu(build_menu())

Gtk.main()

